package com.azzan.springcloud.controller;

import com.azzan.springcloud.entities.CommomResult;
import com.azzan.springcloud.entities.Payment;
import com.azzan.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
public class PaymentController {
    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverport;

    @PostMapping(value = "/payment/create")
    public CommomResult create(@RequestBody Payment payment){
       int result = paymentService.create(payment);
       log.info("插入结果"+result);
       if (result>0){
           return new CommomResult(200,"数据插入成功,serverport:"+serverport, result);
       }else {
           return new CommomResult(400,"数据插入失败",null);
       }

    }
    @GetMapping(value = "/payment/get/{id}")
    public CommomResult getPaymentById(@PathVariable("id") Long id){
      Payment payment = paymentService.getPaymentById(id);
      if (payment != null){
          return  new CommomResult(200,"查询成功,serverport:"+serverport,payment);
      }else {
          return  new CommomResult(400,"查询失败+id="+id,null);

      }
    }
}
